﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Garlic.CC.BaseClass;
using Garlic.CC.Utility;
using Garlic.BLL.Common;
using Garlic.DM.DataModel;
using Garlic.CC.WebUtility;
using Garlic.BLL;
using System.Collections.Generic;

public partial class SystemManagement_EventLogDXYil : BasePage
{
    

    #region Page_Load
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!Page.IsPostBack)
            {
                this.MainFormView.DefaultMode = FormViewMode.ReadOnly;
                PageInit();
            }
        }
        catch (Exception ex)
        {
            this.HandleException(ex);
        }
    }

    /// <summary>
    /// PageInit
    /// </summary>
    /// <param name="msg"></param>
    private void PageInit()
    {
        string type = "";
        string event_log_sn = "";
        event_log_sn = this.Request.QueryString["event_log_sn"];
        type = this.Request.QueryString["type"];
        if (string.IsNullOrEmpty(event_log_sn) || string.IsNullOrEmpty(type))
        {
            this.ShowMessage("页面需要事件标识符和页面类型参数！");
        }

        //Label初始化
        LabelInit(type);

        //数据初始化
        DataInit(event_log_sn);

    }

    /// <summary>
    /// LabelInit
    /// </summary>
    /// <param name="msg"></param>
    private void LabelInit(string type)
    {
        ((Label)this.MainFormView.FindControl("Event_log_sn")).Text = "事件日志序号：";
        ((Label)this.MainFormView.FindControl("Event_time")).Text = "事件时间：";
        ((Label)this.MainFormView.FindControl("Event_id")).Text = "事件标识符：";
        ((Label)this.MainFormView.FindControl("Event_state")).Text = "事件状态：";
        ((Label)this.MainFormView.FindControl("Event_type")).Text = "事件类型：";
        ((Label)this.MainFormView.FindControl("Event_level")).Text = "事件级别：";
        ((Label)this.MainFormView.FindControl("Event_source")).Text = "事件来源：";
        ((Label)this.MainFormView.FindControl("Event_brief")).Text = "事件简述：";
        ((Label)this.MainFormView.FindControl("Event_dXYil")).Text = "事件详述：";
        ((Label)this.MainFormView.FindControl("Event_disposal")).Text = "事件处理描述：";
        ((Label)this.MainFormView.FindControl("Event_parameter1")).Text = "事件参数1：";
        if (type == "1")
        {
            ((Label)this.MainFormView.FindControl("Event_parameter2")).Text = "工厂编号：";
            ((Label)this.MainFormView.FindControl("Event_parameter3")).Text = "车间编号：";
            ((Label)this.MainFormView.FindControl("Event_parameter4")).Text = "送货区域编号：";
            ((Label)this.MainFormView.FindControl("Event_parameter5")).Text = "零件号：";
            ((Label)this.MainFormView.FindControl("Event_parameter6")).Text = "按钮编号：";
            ((Label)this.MainFormView.FindControl("Event_parameter7")).Text = "任务序号：";
        }
        else if (type == "2")
        {
            ((Label)this.MainFormView.FindControl("Event_parameter2")).Text = "工厂编号：";
            ((Label)this.MainFormView.FindControl("Event_parameter3")).Text = "车间编号：";
            ((Label)this.MainFormView.FindControl("Event_parameter4")).Text = "供应商编号：";
            ((Label)this.MainFormView.FindControl("Event_parameter5")).Text = "料架编号：";
            ((Label)this.MainFormView.FindControl("Event_parameter6")).Text = "事件参数6：";
            ((Label)this.MainFormView.FindControl("Event_parameter7")).Text = "事件参数7：";
        }
        else if (type == "3")
        {
            ((Label)this.MainFormView.FindControl("Event_parameter2")).Text = "工厂编号：";
            ((Label)this.MainFormView.FindControl("Event_parameter3")).Text = "车间编号：";
            ((Label)this.MainFormView.FindControl("Event_parameter4")).Text = "供应商编号：";
            ((Label)this.MainFormView.FindControl("Event_parameter5")).Text = "送货路线编号：";
            ((Label)this.MainFormView.FindControl("Event_parameter6")).Text = "零件类型：";
            ((Label)this.MainFormView.FindControl("Event_parameter7")).Text = "事件参数7：";
        }
        else if (type == "4" || type == "5")
        {
            ((Label)this.MainFormView.FindControl("Event_parameter2")).Text = "事件参数2：";
            ((Label)this.MainFormView.FindControl("Event_parameter3")).Text = "事件参数3：";
            ((Label)this.MainFormView.FindControl("Event_parameter4")).Text = "事件参数4：";
            ((Label)this.MainFormView.FindControl("Event_parameter5")).Text = "事件参数5：";
            ((Label)this.MainFormView.FindControl("Event_parameter6")).Text = "事件参数6：";
            ((Label)this.MainFormView.FindControl("Event_parameter7")).Text = "事件参数7：";
        }        
        ((Label)this.MainFormView.FindControl("Event_parameter8")).Text = "事件参数8：";
        ((Label)this.MainFormView.FindControl("Event_parameter9")).Text = "事件参数9：";
        ((Label)this.MainFormView.FindControl("Event_parameter10")).Text = "事件参数10：";
    }

    /// <summary>
    /// DataInit
    /// </summary>
    /// <param name="msg"></param>
    private void DataInit(string event_log_sn)
    {
        this.formViewObjectDataSource.SelectParameters["event_log_sn"].DefaultValue = "event_log_sn = '" + event_log_sn + "'";          
    }
    #endregion    

    #region tool method
    /// <summary>
    /// show message 
    /// </summary>
    /// <param name="msg"></param>
    private void ShowMessage(string msg)
    {
        this.Message = msg;
    }
    #endregion

    protected void MainFormView_DataBound(object sender, EventArgs e)
    {
        try
        {
            //翻译事件名称
            List<CodeDetailInfo> CodeDetailEventInfo = CodeDetailManager.GetList("code_name = 'event_cname'", "");
            if (CodeDetailEventInfo != null)
            {
                for (int i = 0; i < CodeDetailEventInfo.Count; i++)
                {
                    if (CodeDetailEventInfo[i].Code_value == ((Label)this.MainFormView.FindControl("lbEvent_id")).Text)
                    {
                        ((Label)this.MainFormView.FindControl("lbEvent_id")).Text = string.Format(CodeDetailEventInfo[i].Value_cdescription);
                        break;
                    }
                }
            }

            //翻译事件状态
            List<CodeDetailInfo> CodeDetailStateInfo = CodeDetailManager.GetList("code_name = 'event_state'", "");
            if (CodeDetailStateInfo != null)
            {
                for (int i = 0; i < CodeDetailStateInfo.Count; i++)
                {
                    if (CodeDetailStateInfo[i].Code_value == ((Label)this.MainFormView.FindControl("lbEvent_state")).Text)
                    {
                        ((Label)this.MainFormView.FindControl("lbEvent_state")).Text = string.Format(CodeDetailStateInfo[i].Value_cdescription);
                        break;
                    }
                }
            }

            //翻译事件类型
            List<CodeDetailInfo> CodeDetailTypeInfo = CodeDetailManager.GetList("code_name = 'event_type'", "");
            if (CodeDetailTypeInfo != null)
            {
                for (int i = 0; i < CodeDetailTypeInfo.Count; i++)
                {
                    if (CodeDetailTypeInfo[i].Code_value == ((Label)this.MainFormView.FindControl("lbEvent_type")).Text)
                    {
                        ((Label)this.MainFormView.FindControl("lbEvent_type")).Text = string.Format(CodeDetailTypeInfo[i].Value_cdescription);
                        break;
                    }
                }
            }

            //翻译事件级别
            List<CodeDetailInfo> CodeDetailLevelInfo = CodeDetailManager.GetList("code_name = 'event_level'", "");
            if (CodeDetailLevelInfo != null)
            {
                for (int i = 0; i < CodeDetailLevelInfo.Count; i++)
                {
                    if (CodeDetailLevelInfo[i].Code_value == ((Label)this.MainFormView.FindControl("lbEvent_level")).Text)
                    {
                        ((Label)this.MainFormView.FindControl("lbEvent_level")).Text = string.Format(CodeDetailLevelInfo[i].Value_cdescription);
                        break;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            this.HandleException(ex);
        }
    }
}
